#!/usr/bin/python2.5
#-*- coding: gb2312 -*-
"""
needs python 2.5 or upper, but not tested in 3000
"""

from wsgiref.simple_server import WSGIServer, WSGIRequestHandler

from wsgi_handler import application

def start_server(addr):
    wsgi_server = WSGIServer(addr, WSGIRequestHandler)
    wsgi_server.set_app(application)
    wsgi_server.serve_forever()

if __name__ == "__main__":
    import sys
    paras = sys.argv[1:]
    if len(paras) == 1:
        host = '127.0.0.1'
        port = paras[0]
    elif len(paras) == 2:
        host, port = paras
        port = port
    else:
        host = '127.0.0.1'
        port = 8080

    port = int(port)

    try:
        start_server((host, port))
    except KeyboardInterrupt:
        pass

